package com.typhoon.spring_shiro.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.typhoon.spring_shiro.dto.PermissionDto;
import com.typhoon.spring_shiro.entity.PermissionApp;
import com.typhoon.spring_shiro.exception.UnRealizedMethodException;
import com.typhoon.spring_shiro.utils.CollectionUtils;

@Repository("permissionAppDao")
public class PermissionAppDao extends BaseDao implements ICommonDao<PermissionApp, Long> {
	
	private static final String TABLE_PERMISSION_APP = " PermissionApp ";

	@Resource
	private JdbcTemplate financialJdbc;
	
	@Override
	public PermissionApp queryByPrimaryKey(Long primaryKey) {
		throw new UnRealizedMethodException("this method is not realized yet!");
	}

	@Override
	public int deleteByPrimaryKey(Long primaryKey) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public PermissionApp get(Object paramObject) {
		Assert.notNull(paramObject);
		return this.get(financialJdbc, TABLE_PERMISSION_APP, paramObject, PermissionApp.class);
	}

	@Override
	public List<PermissionApp> list(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<PermissionApp> list(Object paramObject) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(PermissionApp paramE) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long count(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long count(Object paramObject) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public PermissionApp save(PermissionApp paramE) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<PermissionApp> listAllByPermissions(List<PermissionDto> permissions) {
		Assert.state(CollectionUtils.isNotEmpty(permissions));
		StringBuilder sql = new StringBuilder();
		List<String> params = new ArrayList<>(permissions.size());
		sql.append(select);
		sql.append(star);
		sql.append(from);
		sql.append(TABLE_PERMISSION_APP);
		sql.append(where);
		sql.append(" permissionCode in ( ");
		PermissionDto permission = null;
		for(int i = 0,size = permissions.size();i < size; i ++) {
			permission = permissions.get(i);
			params.add(permission.getCode());
			sql.append(" ? ");
			if(i < size - 1) {
				sql.append(",");
			}
		}
		sql.append(" )  ");
		return this.queryList(financialJdbc, PermissionApp.class, sql.toString(), params.toArray());
	}
	

}
